<?php

//	Author: 	Christos Polydorou
//	Email:		std04237@di.uoa.gr
//	Purpose: 	Add a new category for a user

require_once ("../DB/connection.php");
require_once ("../DB/defines.php");
require_once ("../Frameworks/Objects/user.php");
require_once ("../Frameworks/Objects/category.php");

function DB_addCategory($category, $userid)
{

    global $conn;

    // The name of the stored procedure
    $sp_name = "usp_addcategory";

    // The return variable
    $retval;

    // Create a new statement
    $stmt = mssql_init($sp_name, $conn);

    // Get values
    $categoryname = $category->GetName();
    $ip = $category->IsPrivate();

    // Bind values
    mssql_bind($stmt, "RETVAL", $retval, SQLINT4, true, false, 1);
    mssql_bind($stmt, '@userid', $userid, SQLINT4, false, false, 1);
    mssql_bind($stmt, '@category_name', $categoryname, SQLVARCHAR, false, false, 50);
    mssql_bind($stmt, '@isprivate', $ip, SQLINT4, false, false, 1);

    // Execute the statement
    $status = mssql_execute($stmt);
//	error_reporting(0);
    if (!$status)
        return DB_ERROR_CATEGORYEXISTS;
    else
        return $retval;
}

?>